#include "version.h"
#include "lds.h"
#include "akfs.h"
#include "symbol.h"

/**
 * @brief 导出akfs操作函数
 */
akfs_operation_t *__akfs_ops = NULL;

/**
 * @brief 链接脚本定义的是变量所在的地址
 */
extern unsigned long int __sym_hook_start;
extern unsigned long int __sym_hook_end;
// 静态初始化
akfs_module_t __process;

static int process_init(void)
{
    int ret = 0;

    __akfs_ops = (akfs_operation_t *)kallsyms_lookup_name(AKFS_OPS_NAME);
    assert_error(__akfs_ops ,-EACCES);

    __akfs_ops->init(&__process ,"process" ,AKFS_DEF_SIZE,
            (unsigned long int)&__sym_hook_start ,
            (unsigned long int)&__sym_hook_end);

    ret = __akfs_ops->reg(&__process);
    assert_error(!ret ,ret);

    return 0;
}

static void process_exit(void){
    __akfs_ops->unreg(&__process);
}

module_init(process_init);
module_exit(process_exit);

MODULE_LICENSE("GPL");
